<template>
  <div>
    <div class="xtx-tabs">
      <ul class="nav">
        <li
          v-for="(item, key) in orderStatus"
          :key="key"
          :class="{ active: item.name === activeName }"
          @click="change(key)"
        >
          {{ item.label }}
        </li>
      </ul>
    </div>
    <div class="order-list">
      <div class="order-item" v-for="(item, key) in mearlist" :key="key">
        <div class="head">
          <span>下单时间：{{ item.createTime }}</span>
          <span>订单编号：{{ item.id }}</span>
          <span class="down-time">
            <i class="iconfont icon-down-time"></i>
            <b>付款截止：{{ item.payLatestTime }}</b>
          </span>
        </div>
        <div class="body">
          <div class="column goods">
            <ul>
              <li v-for="(it, k) in item.skus" :key="k">
                <a class="image" href="javascript:;">
                  <img :src="it.image" alt="" />
                </a>
                <div class="info">
                  <p class="name ellipsis-2">
                    {{ it.name }}
                  </p>
                  <p class="attr ellipsis">
                    <span>{{ it.attrsText }}</span>
                  </p>
                </div>
                <div class="price">¥{{ it.curPrice }}</div>
                <div class="count">x{{ it.quantity }}</div>
              </li>
            </ul>
          </div>
          <div class="column state">
            <p>待付款</p>
          </div>
          <div class="column amount">
            <p class="red">¥{{ item.payMoney }}</p>
            <p>（含运费：¥{{ item.postFee }})</p>
            <p>在线支付</p>
          </div>
          <div class="column action">
            <button type="primary" size="small">立即付款</button>
            <p><a href="javascript:;">查看详情</a></p>
            <p><a href="javascript:;">取消订单</a></p>
          </div>
        </div>
      </div>
    </div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pagelist.page"
      :page-sizes="[5, 10, 20, 100]"
      :page-size="pagelist.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pages"
    >
    </el-pagination>
  </div>
</template>

<script>
import { orderlist } from "@/utils/api/order";

export default {
  data() {
    return {
      activeName: "all",
      orderStatus: [
        { name: "all", label: "全部订单" },
        { name: "unpay", label: "待付款" },
        { name: "deliver", label: "待发货" },
        { name: "receive", label: "待收货" },
        { name: "comment", label: "待评价" },
        { name: "complete", label: "已完成" },
        { name: "cancel", label: "已取消" },
      ],
      pagelist: {
        page: 1,
        pageSize: 5,
        orderState: 0,
      },
      pages: 0,
      mearlist: [],
    };
  },

  mounted() {
    this.getMearlist();
  },

  methods: {
    change(index) {
      this.activeName = index;
      this.getMearlist(index);
    },
    async getMearlist(index) {
      let res = await orderlist({
        page: this.pagelist.page,
        pageSize: this.pagelist.pageSize,

        orderState: index,
      });
      //   console.log(res.result);
      this.mearlist = res.result.items;
      this.pages = res.result.pages;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pagelist.pageSize = val;
      this.getMearlist();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.pagelist.page = val;
      this.getMearlist();
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/css/color.scss";
.xtx-tabs {
  background: #fff;
  > .nav {
    height: 60px;
    line-height: 60px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    > li {
      width: 110px;
      border-right: 1px solid #f5f5f5;
      text-align: center;
      font-size: 16px;
    }
  }
}
.active:hover {
  border-top: 2px solid $xtxColor;
  height: 60px;
  background: #fff;
  line-height: 56px;
}
.order-list {
  background: #fff;
  padding: 20px;
}
.order-item {
  margin-bottom: 20px;
  border: 1px solid #f5f5f5;
  .head {
    height: 50px;
    line-height: 50px;
    background: #f5f5f5;
    padding: 0 20px;
    overflow: hidden;
    span {
      margin-right: 20px;
      &.down-time {
        margin-right: 0;
        float: right;
        i {
          vertical-align: middle;
          margin-right: 3px;
        }
        b {
          vertical-align: middle;
          font-weight: normal;
        }
      }
    }
    .del {
      margin-right: 0;
      float: right;
      color: #999;
    }
  }
  .body {
    display: flex;
    align-items: stretch;
    .column {
      border-left: 1px solid #f5f5f5;
      text-align: center;
      padding: 20px;
      > p {
        padding-top: 10px;
      }
      &:first-child {
        border-left: none;
      }
      &.goods {
        flex: 1;
        padding: 0;
        align-self: center;
        ul {
          li {
            border-bottom: 1px solid #f5f5f5;
            padding: 10px;
            display: flex;
            &:last-child {
              border-bottom: none;
            }
            .image {
              width: 70px;
              height: 70px;
              border: 1px solid #f5f5f5;
            }
            .info {
              width: 220px;
              text-align: left;
              padding: 0 10px;
              p {
                margin-bottom: 5px;
                &.name {
                  height: 38px;
                }
                &.attr {
                  color: #999;
                  font-size: 12px;
                  span {
                    margin-right: 5px;
                  }
                }
              }
            }
            .price {
              width: 100px;
            }
            .count {
              width: 80px;
            }
          }
        }
      }
      &.state {
        width: 120px;
        .green {
          color: $xtxColor;
        }
      }
      &.amount {
        width: 200px;
        .red {
          color: $priceColor;
        }
      }
      &.action {
        width: 140px;
        a {
          display: block;
          &:hover {
            color: $xtxColor;
          }
        }
      }
    }
  }
}
</style>